package com.sudo.common.utils;

import java.util.regex.Pattern;

public class PatternUtil {
    private PatternUtil(){}

    public static final String USERNAME = "^[0-9A-Za-z_]{4,10}$";
    public static final String PASSWORD = "^[0-9A-Za-z_]{6,10}$";
    public static final String ROLE_CODE = "^[0-9A-Za-z_]{4,15}$";
    public static final String DICT_CODE = "^[0-9A-Za-z_]{3,30}$";
    public static final String MENU_CODE = "^[0-9A-Za-z_]{3,30}$";
    public static final String BUTTON_CODE = "^[0-9A-Za-z_]{3,30}$";
    public static final String CAPTCHA = "^[0-9A-Za-z-]{1,4}$";
    /**
     * 网址
     */
    public static final String URL_PATTERN = "^((https|http|ftp|rtsp|mms)?:\\/\\/)[^\\s]+";
    /**
     * 手机号
     */
    public static final String PHONE_PATTERN = "^(13[0-9]|14[5|7]|15[0-9]|18[0-9]|19[4|5])\\d{8}$";
    /**
     * 英文和数字
     */
    public static final String Abc123_PATTERN = "^[A-Za-z0-9]+$";
    /**
     * 4位英文和数字
     */
    public static final String Abc123_PATTERN_4 = "^[A-Za-z0-9]{4}$";
    /**
     * 5位英文和数字
     */
    public static final String Abc123_PATTERN_5 = "^[A-Za-z0-9]{5}$";

    /**
     * 判断字符串非空且为非负整数
     */
    public static final String isNonNegativeInteger = "^[0-9]+[0-9]*$";

    /**
     * 逗号分隔数字
     */
    public static final String commaSplitNumber = "^[1-9][0-9]*([,][1-9][0-9]*)*$";

    /**
     * 邮箱
     */
    public static final String email = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";


    public static boolean isMatches(String patternStr, String str) {
        Pattern pattern = Pattern.compile(patternStr);
        return pattern.matcher(str).matches();
    }

    /**
     * 判断字符串非空且为非负整数
     */
    public static boolean isNonNegativeInteger(String str){
        Pattern pattern = Pattern.compile(isNonNegativeInteger);
        return pattern.matcher(str).matches();
    }
}
